package com.zmn.oms.services.impl.conf.cancel;

import com.zmn.common.dto.StatusDTO;
import com.zmn.oms.model.entity.conf.cancel.OrderCancelCategory;
import com.zmn.oms.model.entity.conf.cancel.OrderCancelCategoryQuery;
import com.zmn.oms.persistence.interfaces.conf.cancel.OrderCancelCategoryDao;
import com.zmn.oms.services.interfaces.conf.cancel.OrderCancelCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author tanbiao
 * @description
 * @since 2019/10/21 18:17
 * @modifier
 **/
@Service
public class OrderCancelCategoryServiceImpl implements OrderCancelCategoryService {
    @Autowired
    private OrderCancelCategoryDao orderCancelCategoryDAO;

    @Override
    public OrderCancelCategory findByKey(int categId) {
        return orderCancelCategoryDAO.findByKey(categId);
    }

    @Override
    public List<OrderCancelCategory> findByKeys(List<Integer> ids) {
        return orderCancelCategoryDAO.findByKeys(ids);
    }

    @Override
    public Integer findMaxSort() {
        return orderCancelCategoryDAO.findMaxSort();
    }

    @Override
    public OrderCancelCategory findByName(String name) {
        return orderCancelCategoryDAO.findByName(name);
    }

    @Override
    public List<OrderCancelCategory> listByQuery(OrderCancelCategoryQuery query) {
        return orderCancelCategoryDAO.listByQuery(query);
    }

    @Override
    public List<OrderCancelCategory> listPageByQuery(OrderCancelCategoryQuery query) {
        return orderCancelCategoryDAO.listPageByQuery(query);
    }

    @Override
    public Integer countByQuery(OrderCancelCategoryQuery query) {
        return orderCancelCategoryDAO.countByQuery(query);
    }

    @Override
    public Integer updateByKey(OrderCancelCategory categ) {
        return orderCancelCategoryDAO.updateByKey(categ);
    }

    @Override
    public Integer updateSortKey(Integer categId, Integer sort, String staffName) {
        OrderCancelCategory cancelCategory = new OrderCancelCategory();
        cancelCategory.setCategId(categId);
        cancelCategory.setSort(sort);
        cancelCategory.setUpdateTime(new Date());
        cancelCategory.setUpdater(staffName);
        return orderCancelCategoryDAO.updateSortKey(cancelCategory);
    }

    @Override
    public Integer updateFirstLetterByKey(Integer categId, String firstLetter, String staffName) {
        OrderCancelCategory cancelCategory = new OrderCancelCategory();
        cancelCategory.setCategId(categId);
        cancelCategory.setFirstLetter(firstLetter);
        cancelCategory.setUpdateTime(new Date());
        cancelCategory.setUpdater(staffName);
        return orderCancelCategoryDAO.updateFirstLetterByKey(cancelCategory);
    }

    @Override
    public int updateStatusBatch(List<Integer> categoryIds, Integer status, String staffName) {
        StatusDTO dto = new StatusDTO();
        dto.setIds(categoryIds);
        dto.setStatus(status);
        dto.setUpdater(staffName);
        dto.setUpdateTime(new Date());
        return orderCancelCategoryDAO.updateStatusBatch(dto);
    }

    @Override
    public Integer insert(OrderCancelCategory category) {
        return orderCancelCategoryDAO.insert(category);
    }

    @Override
    public Integer deleteByKey(Integer categId) {
        return orderCancelCategoryDAO.deleteByKey(categId);
    }
}
